package com.animal.service.impl;

import com.animal.entity.pojo.AUser;
import com.animal.mapper.UserMapper;
import com.animal.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;



import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;


    @Override
    public AUser login(String username, String password) {
        try{
            AUser login = userMapper.login(username, password);
            if (login.getUserName().equals(username) && login.getPassword().equals(password)) {
                return login;
            }else{
                return null;
            }
        }catch (RuntimeException e){
            throw new RuntimeException("用户名密码错误");
        }

    }

    @Override
    public AUser getAdminById(Integer id) {
        return userMapper.getAdminById(id);
    }

    @Override
    public List<AUser> getAdmin(String userName) {
        return userMapper.getAdmin(userName);
    }

    @Override
    public boolean updateAdmin(AUser aUser) {
        int count = userMapper.updateAdmin(aUser);
        if (count>0) {
            return true;
        }else {
            return false;
        }
    }


    @Override
    public boolean addAdmin(AUser aUser) {
        int count = userMapper.addAdmin(aUser);
        if (count>0) {
            return true;
        }else {
            return false;
        }

    }

    @Override
    public boolean deleteAdmin(List<Integer> ids) {
        int count = userMapper.deleteAdmin(ids);
        if (count>0) {
            return true;
        }else {
            return false;
        }

    }

    @Override
    public boolean deleteAdminByid(Integer id) {
        int count = userMapper.deleteAdminByid(id);
        if (count>0) {
            return true;
        }else {
            return false;
        }
    }

    @Override
    public boolean addUser(AUser aUser) {
        int count = userMapper.addUser(aUser);
        if (count>0) {
            return true;
        }
            return false;
    }
    @Override
    public boolean addUser2(AUser aUser) {
        int count = userMapper.addUser2(aUser);
        if (count>0) {
            return true;
        }
        return false;
    }

    @Override
    public List<AUser> getUser(String userName) {
        return userMapper.getUser(userName);
    }

    @Override
    public boolean updateUser(AUser aUser) {
        int count = userMapper.updateUser(aUser);
        if (count>0) {
            return true;
        }
        return false;
    }

    @Override
    public boolean deleteUserByid(Integer id) {
        int count = userMapper.deleteUserByid(id);
        if (count>0) {
            return true;
        }
        return false;
    }

    @Override
    public boolean deleteUser(List<Integer> ids) {
        int count = userMapper.deleteUser(ids);
        if (count>0) {
            return true;
        }
        return false;
    }

    @Override
    public AUser getUserById(Integer id) {
        return userMapper.getUserById(id);
    }

    @Override
    public AUser loginByUser(String userName, String password) {
        try{
            AUser login = userMapper.loginByUser(userName, password);
            if (login.getUserName().equals(userName) && login.getPassword().equals(password)) {
                return login;
            }else{
                return null;
            }
        }catch (RuntimeException e){
            throw new RuntimeException("用户名密码错误");
        }
    }
}
